﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
</head>
<body>
<script type="text/javascript">
// ==================== //
function Polygon(iSides)
{
    this.sides = iSides;
}
Polygon.prototype.getArea = function()
{
    return 0;
}
// ==================== //

// ==================== //
function Triangle(iBase, iHeight)
{
    Polygon.call(this, 3);
    // Polygon.apply(this, [3]);
    this.base = iBase;
    this.height = iHeight;
}
// 在这里，因为只有一个方法，
// Triangle不需要从Polygon继承方法，所以下面这句可以省掉
Triangle.prototype = new Polygon(); 
Triangle.prototype.getArea = function()
{
    return 0.5 * this.base * this.height;
}
// ==================== //

// ==================== //
function Rectangle(iLength, iWidth)
{
    Polygon.call(this, 4);
    this.length = iLength;
    this.width = iWidth;
}
Rectangle.prototype.getArea = function()
{
    return this.length * this.width;
}

var triangle = new Triangle(12, 4);
var rectangle = new Rectangle(22, 10);

alert(triangle.sides);
alert(triangle.getArea());

alert(rectangle.sides);
alert(rectangle.getArea());
// ==================== //
</script>
</body>
</html>
